import React, { useEffect } from 'react';
import { RouterProvider } from 'react-router-dom';
import { App as AntApp } from 'antd';
import { ThemeProvider } from './contexts/ThemeContext';
import { AuthProvider } from './contexts/AuthContext';

import { UniversalNotificationProvider } from './contexts/UniversalNotificationContext';
import { initNotificationConfig } from './config/notification';
import { useGlobalProgressManagerInit } from './utils/globalProgressManager';
import { useGlobalSyncTaskManagerInit } from './utils/globalSyncTaskManagerInit';
import router from './routes';
import 'dayjs/locale/zh-cn';
import './styles/modal-theme.css';



// 全局进度管理器初始化组件
const GlobalProgressManagerInit: React.FC = () => {
  useGlobalProgressManagerInit();
  return null;
};

// 全局同步任务管理器初始化组件
const GlobalSyncTaskManagerInit: React.FC = () => {
  useGlobalSyncTaskManagerInit();
  return null;
};

const App: React.FC = () => {
  useEffect(() => {
    // 立即初始化通知配置
    initNotificationConfig();
  }, []);

  return (
    <ThemeProvider>
      <AuthProvider>
        <AntApp>
          <UniversalNotificationProvider
            maxNotifications={10}
            enablePersistence={true}
            enableAntNotification={true}
          >
            <GlobalProgressManagerInit />
            <GlobalSyncTaskManagerInit />
            <RouterProvider router={router} />
          </UniversalNotificationProvider>
        </AntApp>
      </AuthProvider>
    </ThemeProvider>
  );
};

export default App;
